import React from 'react'
import { SchemaForm, Item, Submit, SchemaType } from '@amazebird/antd-schema-form'
import ArrayItem from './arrayComponent'

const arraySchema = {
  type: 'object',
  fields: {
    name: {
      component: 'Input'
    },
    age: {
      component: 'InputNumber'
    }
  }
}
const schema: SchemaType = {
  array: {
    label: '数组',
    component: ArrayItem,
    props: {
      schema: arraySchema,
      columns: [{ label: '姓名', span: 16, key: 'name' }, { label: '年龄', span: 8, key: 'age' }]
    }
  },
  test: {
    label: '测试',
    component: 'Input'
  }
}

const initialValues = {
  array: [{
    name: 'test',
    age: 10
  }]
}

export default function() {
  function onFinish(data) {
    console.info(data)
  }
  return (
    <SchemaForm schema={schema} initialValues={initialValues}>
      <Item field="array" />
      <Item field="test" />
      <Submit onFinish={onFinish} />
    </SchemaForm>
  )
}
